Skip to content

ReflectionParameter::__construct(): switch @param to typehint #16216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DanielEScherzer
Copy link
Member

The type is checked (though for values of the wrong type a ReflectionException is thrown rather than a TypeError), but the information about the required type is not provided to Reflection. Replace the @param comment with a real typehint so that the information is also available via Reflection.

The type is checked (though for values of the wrong type a
`ReflectionException` is thrown rather than a `TypeError`), but the
information about the required type is not provided to Reflection. Replace the
`@param` comment with a real typehint so that the information is also available
via Reflection.
@@ -638,8 +638,7 @@ class ReflectionParameter implements Reflector
/** @implementation-alias ReflectionClass::__clone */
private function __clone(): void {}

/** @param string|array|object $function */
public function __construct($function, int|string $param) {}
public function __construct(string|array|object $function, int|string $param) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is

zend_argument_error(reflection_exception_ptr, 1, "must be a string, an array(class, method), or a callable object, %s given", zend_zval_value_name(reference));
dead code then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, since it is still reached in

try {
new ReflectionParameter(0, 0);
}
catch(ReflectionException $e) {
printf( "Ok - %s\n", $e->getMessage());
}
echo "Done.\n";
?>
--EXPECT--
Class "A" does not exist
Method C::b() does not exist
Method C::b() does not exist
Ok - ReflectionParameter::__construct() expects exactly 2 arguments, 1 given
Ok - ReflectionParameter::__construct(): Argument #1 ($function) must be a string, an array(class, method), or a callable object, int given

The parameter is still parsed via Z_PARAM_ZVAL, rather than enforcing the types as part of the parsing

@iluuu1994
Copy link
Member

iluuu1994 commented Feb 7, 2025

@kocsismate Can you verify if this is ok? Edit: I guess the feedback will be similar as with GH-16218, we should have consistent errors for parameter parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants